<?php
/**
 * Created by PhpStorm.
 * User: MCAT
 * Date: 2018/11/6
 * Time: 16:34
 */

namespace app\api\controller;


class FindInfo extends StoneflyBase
{
    protected  $type= 1;
    protected  $area= 1;
    protected  $style= 1;
    public function findCmp($typeid=3,$areaid=7,$styleid=1){
        $this->area=$areaid;
        $this->type=$typeid;
        $this->style=$styleid;

        $result = db('company')->where(function ($query) {//多条件闭包函数查询
            $query->whereOr('areaid', 'like', $this->area)
                ->whereOr('areaid', 'like', '%,'.$this->area.',%')
                ->whereOr('areaid', 'like', $this->area.',%')
                ->whereOr('areaid', 'like', '%,'.$this->area);
        })->where(function ($query) {
            $query->whereOr('typeid', 'like', $this->type)
                ->whereOr('typeid', 'like', '%,'.$this->type.',%')
                ->whereOr('typeid', 'like', $this->type.',%')
                ->whereOr('typeid', 'like', '%,'.$this->type);
        })->where(function ($query) {
            $query->whereOr('styleid', 'like', $this->style)
                ->whereOr('styleid', 'like', '%,'.$this->style.',%')
                ->whereOr('styleid', 'like', $this->style.',%')
                ->whereOr('styleid', 'like', '%,'.$this->style);
        }) ->select();
       if ($result){
           foreach ($result as $key => $value){

               $result[$key]['imgs']=$this->srcSpl(explode('|',$result[$key]['imgs']));
               $result[$key]['logo']=$this->srcSpl($result[$key]['logo']);
               $result[$key]['banner']=$this->srcSpl(explode('|',$result[$key]['banner']));
           }
           return json(['msg'=>'查到'.sizeof($result).'家装修公司','data'=>$result,'code'=>200]);
       }else return json(['么有查到装修公司，请修改条件重查','data'=>$result,'code'=>202]);

    }

    public function srcSpl($str){//掉用补全图片路径
        if ($str){
            if (is_array($str)){//如果是数组
                foreach ($str as  $key => $value){//循环补全路径
                    $str[$key]=$this->SpliceSrc($value);
                }
            }
            else{//不是数组
                $str=$this->SpliceSrc($str);//直接补全路径
            }
        }

        return $str;
    }



}